<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>添加收款记录</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var saleOrderId = new Ext.form.Hidden({
          name: 'sale_order_id',
          value: '<%=params[:id]%>'
        });
        
        var saleAmount = new Ext.form.NumberField({
          fieldLabel: '销售金额',
          name:"sale_amount",
          allowBlank: false,
          allowDecimals: true,
          allowNegative: false,
          value:<%=@saleAmount%>,
          readOnly:true,
          anchor: '90%'
        });
        
        var totalAmount = new Ext.form.NumberField({
          fieldLabel: '已收金额',
          name:"tatol_amount",
          allowBlank: false,
          allowDecimals: true,
          allowNegative: false,
          value:<%=@amount%>,
          readOnly:true,
          anchor: '90%'
        });
        
        //首付金额
        var recAmount = new Ext.form.NumberField({
          fieldLabel: '收款金额',
          name:"amount",
          allowBlank: false,
          allowDecimals: true,
          allowNegative: false,
          anchor: '90%'
        });

        var paymentTypeStore = new Ext.data.ArrayStore({
          //fields: ['value', 'text'],
          fields: ['text'],
          data : paymentTypeArray
        });

        var paymentType = new Ext.form.ComboBox({
          fieldLabel: '收款方式',
          store: paymentTypeStore,
          valueField:'text',
          displayField:'text',
          typeAhead: true,
          mode: 'local',
          triggerAction: 'all',
          selectOnFocus:true,
          name:'payment_type',
          emptyText:'请选择收款方式...',
          allowBlank: false,
          anchor: '95%'
        });

        var actionDate = new Ext.form.DateField({
          fieldLabel: '收款日期',
          name: 'action_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: false,
          blankText: "收款日期必须选择",
          emptyText: '收款日期...',
          anchor: '90%'
        });
        
        //收款备注
        var desc = new Ext.form.TextField({
          fieldLabel: '收款备注',
          name: 'description',
          anchor: '95%'
        });

        var submitButton = new Ext.Button({
          text: '提交',
          iconCls: 'finding',
          handler: function(){
            if (newReceivableForm.form.isValid()) {
              this.disable();
              newReceivableForm.form.submit({
                method: 'GET',
                success: function(result, response){
                  if (response.result.info == "成功") {
                    //添加成功后，隐藏窗口，并刷新Grid
                    newReceivableWin.destroy();
                  }
                  else {
                    Ext.MessageBox.alert('消息', response.result.info);
                  }
                },
                failure: function(result, response){
                  Ext.MessageBox.alert('提示', result.responseText);
                  newReceivableWin.destroy();
                }
              });
            }
            else {
              Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
            }
          }
        });
        
        var newReceivableForm = new Ext.FormPanel({
          labelWidth: 55, // label settings here cascade unless overridden
          url:'/receivables/create',
          frame:true,
          //title: '添加用户',
          bodyStyle:'padding:5px 5px 0',
          width: 550,
          //height:300,
          items: [{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .3,
                  layout: 'form',
                  border: false,
                  items: [saleAmount]
                }, {
                  columnWidth: .35,
                  layout: 'form',
                  border: false,
                  items: [totalAmount]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .3,
                  layout: 'form',
                  border: false,
                  items: [recAmount]
                }, {
                  columnWidth: .35,
                  layout: 'form',
                  border: false,
                  items: [paymentType]
                }, {
                  columnWidth: .35,
                  layout: 'form',
                  border: false,
                  items: [actionDate]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [desc]
                }]
            },saleOrderId],
          buttons: [submitButton,{
              text: '关闭',
              iconCls: 'exit',
              handler: function(){
                newReceivableWin.destroy();
              }
            }]
        });
        newReceivableForm.render('new_receivable_form');
        if (totalAmount.getValue() > saleAmount.getValue() || totalAmount.getValue() == saleAmount.getValue() ){
          submitButton.disable();
        }
      })
    </script>
  </head>
  <body>
    <div id="new_receivable_form"></div>
  </body>
</html>
